/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package algebra;

import java.util.ArrayList;

/**
 *
 * @author BIM1LA
 */
public class Vector {

    int rows;
    private ArrayList<Double> vectorset;

    public Vector(int rows) {

        this.rows = rows;
        vectorset = new ArrayList<Double>(rows);
        
        for (int i = 0; i < rows; i++) {
            
            vectorset.add(0.);

        }


    }
    
    public Vector(int rows, double init_value) {

        this.rows = rows;
        vectorset = new ArrayList<Double>(rows);
        
        for (int i = 0; i < rows; i++) {
            
            vectorset.add(init_value);

        }


    }

    public boolean set(int i, double data) {

        if (i > rows) {
            return false;
        } else {

            vectorset.set(i, data);
            return true;
        }

    }
    
     public boolean set(int i, Vector data) {

        if (i > rows) {
            return false;
        } else {
          
            for (int j = 0; j < data.getrows(); j++) {
                
                vectorset.set(i+j, data.get(j));
                
            }
            
          
            return true;
        }

    }
    
    public double get(int i){
    
    if(i>rows){
        System.out.println("Fehler: i > Spaltenanzahl Vektor");
        return Double.NaN;
    }
    else{
    
        return vectorset.get(i);
    
    }
    }
    
    public int size(){return rows;}
    
    public Vector minus(Vector vec){
    
    if(this.size()!=vec.size()) return null;
    else{
    
    Vector retvec = new Vector(rows);
    
        for (int i = 0; i < rows; i++) {
            
            retvec.set(i, this.get(i)-vec.get(i));
            
        }
    return retvec;
    }
    }
    
      public Vector plus(Vector vec){
    
    if(this.size()!=vec.size()) return null;
    else{
    
    Vector retvec = new Vector(rows);
    
        for (int i = 0; i < rows; i++) {
            
            retvec.set(i, this.get(i)+vec.get(i));
            
        }
    return retvec;
    }
    }
    
    public Vector mul(double t){
    
    Vector vec = new Vector(rows);
    
        for (int i = 0; i < rows; i++) {
            
            vec.set(i, this.get(i)*t);
            
        }
    return vec;
    }
    
        public void mul_no(double t){
    
    
    
        for (int i = 0; i < rows; i++) {
            
            this.set(i, this.get(i)*t);
            
        }
   
    }
        
        
        public Vector scalar(Vector ne){
        
            Vector retvec = new Vector(rows);
            
            for (int i = 0; i < rows; i++) {
                
                retvec.set(i, this.get(i)*ne.get(i));
            }
        return retvec;
        
        }
        
    
    
    public int getrows(){return rows;}
    
    public void insertrow(){
    
        System.out.println("noch nicht implementiert");
    
    }
    
    public ArrayList<Double> getarraylist(){return vectorset;}
    
        
    public String toString(){
    
       String s = "";
        
        for (int i = 0; i < rows; i++) {
    
                s += Double.toString(this.get(i))+" \n";
        }
        
    return s;

    }
    
    
    public static void main(String[] args) {
        
        Vector vec = new Vector(3, 1);
        System.out.println(vec);
        
    }
}
